package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: ShoppingCartController
 * Package:
 * Description
 * 购物车
 *
 * @Author xw
 * @Create 2023/11/23 20:03
 */

@RestController("ShoppingCartController")
@Slf4j
@RequestMapping("/user/shoppingCart")
@Api(tags = "PC 购物车接口")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;


    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        log.info("添加购物车，商品星系为：{}", shoppingCartDTO);

        // 添加购物车
        shoppingCartService.add(shoppingCartDTO);

        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result showShoppingCart() {
        log.info("查看购物车");
        return Result.success(shoppingCartService.showShoppingCart());
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result<String> cleanShoppingCart(){
        log.info("清空购物车");
        shoppingCartService.cleanShoppingCart();

        return Result.success();
    }


    @PostMapping("/sub")
    @ApiOperation("删除购物车中一个商品")
    public Result<String> deleteNoeShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("删除购物车中一个商品：{}",shoppingCartDTO);

        shoppingCartService.deleteNoeShoppingCart(shoppingCartDTO);


        return Result.success();
    }



}
